package edu.msg.hrappy.backend.service.beans;

import java.util.Collections;
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.EJB;

import edu.msg.hrappy.backend.model.Job;
import edu.msg.hrappy.backend.repository.JobRepository;
import edu.msg.hrappy.backend.repository.exception.RepositoryException;
import edu.msg.hrappy.backend.service.JobService;
import edu.msg.hrappy.backend.service.exception.ServiceException;

@Stateless
public class JobServiceBean implements JobService {

    @EJB
    private JobRepository jobDAO;

    @Override
    public void insert(Job obj) {

        try {
            jobDAO.insert(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void update(Job obj) {
        try {
            jobDAO.update(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void delete(Job obj) {
        try {
            jobDAO.delete(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public List<Job> getAll() {
        List<Job> all = Collections.emptyList();
        try {
            all = jobDAO.getAll();
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return all;
    }

    @Override
    public Job getById(Long id) {
        Job one;
        try {
            one = jobDAO.getById(id);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return one;
    }

}
